package PMIRPConstDefs;

/**
 * Generated from IDL union "Schedule".
 *
 * @author JacORB IDL compiler V 2.3.0, 17-Feb-2007
 * @version generated at 2013-5-20 22:07:19
 */

public final class ScheduleHelper
{
	private static org.omg.CORBA.TypeCode _type;
	public static void insert (final org.omg.CORBA.Any any, final PMIRPConstDefs.Schedule s)
	{
		any.type(type());
		write( any.create_output_stream(),s);
	}

	public static PMIRPConstDefs.Schedule extract (final org.omg.CORBA.Any any)
	{
		return read(any.create_input_stream());
	}

	public static String id()
	{
		return "IDL:PMIRPConstDefs/Schedule:1.0";
	}
	public static Schedule read (org.omg.CORBA.portable.InputStream in)
	{
		Schedule result = new Schedule ();
		PMIRPConstDefs.ScheduleType disc = PMIRPConstDefs.ScheduleType.from_int(in.read_long());
		switch (disc.value ())
		{
			case PMIRPConstDefs.ScheduleType._DAILY:
			{
				PMIRPConstDefs.IntervalOfDay[] _var;
				_var = PMIRPConstDefs.DailySchedulingHelper.read(in);
				result.daily_scheduling (_var);
				break;
			}
			case PMIRPConstDefs.ScheduleType._WEEKLY:
			{
				PMIRPConstDefs.WeeklySchedulingElement[] _var;
				_var = PMIRPConstDefs.WeeklySchedulingHelper.read(in);
				result.weekly_scheduling (_var);
				break;
			}
		}
		return result;
	}
	public static void write (org.omg.CORBA.portable.OutputStream out, Schedule s)
	{
		out.write_long (s.discriminator().value ());
		switch (s.discriminator().value ())
		{
			case PMIRPConstDefs.ScheduleType._DAILY:
			{
				PMIRPConstDefs.DailySchedulingHelper.write(out,s.daily_scheduling ());
				break;
			}
			case PMIRPConstDefs.ScheduleType._WEEKLY:
			{
				PMIRPConstDefs.WeeklySchedulingHelper.write(out,s.weekly_scheduling ());
				break;
			}
		}
	}
	public static org.omg.CORBA.TypeCode type ()
	{
		if (_type == null)
		{
			org.omg.CORBA.UnionMember[] members = new org.omg.CORBA.UnionMember[2];
			org.omg.CORBA.Any label_any;
			label_any = org.omg.CORBA.ORB.init().create_any ();
			PMIRPConstDefs.ScheduleTypeHelper.insert(label_any, PMIRPConstDefs.ScheduleType.DAILY);
			members[0] = new org.omg.CORBA.UnionMember ("daily_scheduling", label_any, PMIRPConstDefs.DailySchedulingHelper.type(),null);
			label_any = org.omg.CORBA.ORB.init().create_any ();
			PMIRPConstDefs.ScheduleTypeHelper.insert(label_any, PMIRPConstDefs.ScheduleType.WEEKLY);
			members[1] = new org.omg.CORBA.UnionMember ("weekly_scheduling", label_any, PMIRPConstDefs.WeeklySchedulingHelper.type(),null);
			 _type = org.omg.CORBA.ORB.init().create_union_tc(id(),"Schedule",PMIRPConstDefs.ScheduleTypeHelper.type(), members);
		}
		return _type;
	}
}
